package presentacion;

import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextArea;
import javax.swing.border.EmptyBorder;
import java.awt.Window;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.GridBagLayout;
import javax.swing.JTextField;
import javax.swing.JButton;

import negocio.TransferPublicidad;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;

public class GUINuevaClase extends JDialog {

	private JPanel contentPane;
	private JTextField tbClase;
	private TransferPublicidad _datos;
	private JButton bAceptar;

	/**
	 * Create the frame.
	 */
	public GUINuevaClase(){
		setRootPaneCheckingEnabled(false);
		setModal(true);
		setTitle("Nueva Clase");
		setResizable(false);
		setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
		setBounds(100, 100, 394, 67);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);
		
		tbClase = new JTextField();
		tbClase.addKeyListener(new KeyAdapter() {
			@Override
			public void keyPressed(KeyEvent key) {
				if ( key.getKeyChar() == key.VK_ENTER ) { //presiona enter
					if (tbClase.getText().isEmpty() ) {
						JOptionPane.showMessageDialog(new JTextArea(), "El campo clase esta vacio");
						return;
					}
					else
						_datos.setClase(tbClase.getText());
					dispose();
				}
			}
		});
		tbClase.setBounds(10, 11, 265, 20);
		contentPane.add(tbClase);
		tbClase.setColumns(10);
		
		bAceptar = new JButton("Aceptar");
		bAceptar.setBounds(285, 10, 89, 23);
		bAceptar.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent e) {
				if (tbClase.getText().isEmpty() ) {
					JOptionPane.showMessageDialog(new JTextArea(), "El campo clase esta vacio");
					return;
				}
				else
					_datos.setClase(tbClase.getText());
				dispose();
			}
		});
		contentPane.add(bAceptar);
	}

	public void setDatos (TransferPublicidad datos) { _datos = datos; }
}
